﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RouletteGame
{
    public interface IBet
    {
        string PlayerName { get; }
        uint Amount { get; }
        uint WonAmount(Field field);
    }

    public abstract class Bet : IBet
    {
        public string PlayerName { get; private set; }
        public uint Amount { get; private set; }

        protected Bet(string name, uint amount)
        {
            PlayerName = name;
            Amount = amount;
        }

        public abstract uint WonAmount(Field field);
    }

    public class FieldBet : Bet
    {
        private uint FieldNumber { get; set; }

        public FieldBet(string name, uint amount, uint field)
            : base(name, amount)
        {
            FieldNumber = field;
        }

        public override uint WonAmount(Field field)
        {
            return field.Number == FieldNumber ? 36 * Amount : 0;
        }

        public override string ToString()
        {
            return string.Format(Amount + "$ field bet on " + FieldNumber);
        }
    }

    public class ColorBet : Bet
    {
        private uint Color { get; set; }

        public ColorBet(string name, uint amount, uint color)
            : base(name, amount)
        {
            Color = color;
        }

        public override uint WonAmount(Field field)
        {
            if (Color == 2 && field.Color == Color)
            {
                return 36*Amount;
            }

            return field.Color == Color ? 2 * Amount : 0;
        }

        public override string ToString()
        {
            string colorToString;

            switch (Color)
            {
                case Field.Black: colorToString = "black"; break;
                case Field.Red: colorToString = "red"; break;
                case Field.Green: colorToString = "green"; break;
                default: throw new ArgumentException("Invalid color");
            }

            return string.Format(Amount + "$ color bet on " + colorToString);
        }
    }

    public class EvenOddBet : Bet
    {
        private bool Even { get; set; }

        public EvenOddBet(string name, uint amount, bool even)
            : base(name, amount)
        {
            Even = even;
        }

        public override uint WonAmount(Field field)
        {
            return field.Even == Even ? 2 * Amount : 0;
        }

        public override string ToString()
        {
            var evenOddString = Even ? "even" : "odd";

            return string.Format(Amount + "$ even/odd bet on " + evenOddString);
        }
    }
}